package com.yunkeji.admin.controller.broker;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.yunkeji.common.annotation.Log;
import com.yunkeji.common.core.controller.BaseController;
import com.yunkeji.common.core.domain.R;
import com.yunkeji.common.enums.BusinessType;
import com.yunkeji.dao.domain.broker.BrokerMenu;
import com.yunkeji.system.service.IBrokerMenuService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 推广用户信息
 *
 *
 * @author 雷擎宇
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/broker/menu")
public class BrokerMenuController extends BaseController {

    private final IBrokerMenuService menuService;

    /**
     * 获取菜单列表
     */
    @SaCheckPermission("broker:menu:list")
    @GetMapping("/list")
    public R<List<BrokerMenu>> list() {
        List<BrokerMenu> menus = menuService.selectMenuList();
        return R.ok(menus);
    }


    /**
     * 新增菜单
     */
    @SaCheckPermission("broker:menu:add")
    @Log(title = "新增推广菜单", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@RequestBody BrokerMenu user) {
        return toAjax(menuService.insertMenu(user));
    }

    /**
     * 修改菜单
     */
    @SaCheckPermission("broker:menu:edit")
    @Log(title = "修改推广菜单", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@RequestBody BrokerMenu user) {
        return toAjax(menuService.updateMenu(user));
    }

    /**
     * 删除菜单
     */
    @SaCheckPermission("broker:menu:remove")
    @Log(title = "删除推广菜单", businessType = BusinessType.UPDATE)
    @DeleteMapping("/{menuId}")
    public R<Void> delete(@PathVariable Long menuId) {
        return toAjax(menuService.deleteMenuById(menuId));
    }

}
